#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>

int cmp(void const* a, void const* b) {
    return *(int*)a > *(int*)b;
}
int findLHS(int* nums, int numsSize) {
    qsort(nums, numsSize, sizeof(int), cmp);
    int max = 0;
    int begin = 0, end = 0;
    for (end = 0; end < numsSize; end++) {
        if (nums[end] - nums[begin] > 1) {
            begin++;
        }
        if (nums[end] - nums[begin] == 1) {
            max = fmax(max, end - begin + 1);
        }
    }
    return max;
}
int main()
{
    //int a[] = { 1,1,1,1 };
    int a[] = { 1,3,2,2,5,2,3,7 };
    int ret = findLHS(a, 8);
    printf("%d\n", ret);
    return 0;
}